package com.zwh.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class CorsConfig {
    //处理跨域
    @Bean
    public CorsWebFilter corsWebFilter(){
        CorsConfiguration configuration = new CorsConfiguration();
        //允许的请求方法：get head post put patch delete options trace
        configuration.addAllowedMethod("*");
        //允许的请求源
        configuration.addAllowedOrigin("*");
        //允许的请求头
        configuration.addAllowedHeader("*");
        //url映射
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**",configuration);
        return new CorsWebFilter(source);
    }
}
